package com.project.rule.service;


import com.project.entity.UserEntity;
import org.apache.commons.lang3.StringUtils;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/drools")
public class Controller {


    @Resource
    KieBase kieBase;

    @RequestMapping("/test")
    public String test(){
        // 修改:

        KieSession kieSession = kieBase.newKieSession();
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername("123");
        kieSession.insert(userEntity);
        int ret = kieSession.fireAllRules();
        kieSession.dispose();
        return String.valueOf(ret);
    }

    public static void main(String[] args) {
        String str = "A2D";
        str = StringUtils.substring(str,0,2);
        System.out.println("str = " + str);
    }


}
